﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Configuration;
using System.Reflection;
using DAL;
using Common;


public partial class Customer_Document : System.Web.UI.Page
{
    protected string MenuType
    {
        get { return string.IsNullOrEmpty(Request["menutype"]) ? "" : Request["menutype"].ToString(); }
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        DocDataBind();
    }

    private void DocDataBind()
    {
        lv_Doc.DataSourceID = DocOBJ.ID;
        lv_Doc.DataBind();
    }

    //搜索
    protected void submit_Click(object sender, EventArgs e)
    {
       
    }


   
    //DropDownList分页选择
    protected void PageList_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList pagelist = (DropDownList)sender;

        int CurPage = Convert.ToInt32(pagelist.SelectedValue);
        int TotalPage = WebUtility.GetTotalPage(DataPager1.TotalRowCount, DataPager1.PageSize);

        DataPager1.SetPageProperties((CurPage - 1) * DataPager1.PageSize, DataPager1.PageSize, true);
    }


    protected void lv_Doc_DataBound(object sender, EventArgs e)
    {
        //Page Binding
        DropDownList pagelist = (DropDownList)DataPager1.Controls[4].FindControl("PageList");

        int CurPage = WebUtility.GetCurrentPage(DataPager1.StartRowIndex, DataPager1.PageSize);
        int TotalPage = WebUtility.GetTotalPage(DataPager1.TotalRowCount, DataPager1.PageSize);
        for (int i = 1; i <= TotalPage; i++)
            pagelist.Items.Add(new ListItem("第" + i.ToString() + "页", i.ToString()));
        pagelist.SelectedValue = CurPage.ToString();
    }


    protected void lv_Doc_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        //InfoServer Binding
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            ListView lv_InfoServer = (ListView)e.Item.FindControl("lv_InfoServer");

            lv_InfoServer.DataSource = new Document<InfoServer>().SelectDoc(CustName.Text.Trim(),Keyword.Text.Trim());
            lv_InfoServer.DataBind();

            ListView lv_InfoClient = (ListView)e.Item.FindControl("lv_InfoClient");
            lv_InfoClient.DataSource = new Document<InfoClient>().SelectDoc(CustName.Text.Trim(), Keyword.Text.Trim());
            lv_InfoClient.DataBind();

            ListView lv_InfoDevice = (ListView)e.Item.FindControl("lv_InfoDevice");
            lv_InfoDevice.DataSource = new Document<InfoDevice>().SelectDoc(CustName.Text.Trim(), Keyword.Text.Trim());
            lv_InfoDevice.DataBind();

            ListView lv_InfoOffice = (ListView)e.Item.FindControl("lv_InfoOffice");
            lv_InfoOffice.DataSource = new Document<InfoOffice>().SelectDoc(CustName.Text.Trim(), Keyword.Text.Trim());
            lv_InfoOffice.DataBind();

            ListView lv_InfoSoft = (ListView)e.Item.FindControl("lv_InfoSoft");
            lv_InfoSoft.DataSource = new Document<InfoSoft>().SelectDoc(CustName.Text.Trim(), Keyword.Text.Trim());
            lv_InfoSoft.DataBind();
        }
    }

    //Delete

    protected void lv_InfoServer_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int ServerKey = Convert.ToInt32(((ListView)sender).DataKeys[e.ItemIndex].Value);
        new Document<InfoServer>().DelDoc<InfoServer>(ServerKey);
    }

    protected void lv_InfoClient_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int ClientKey = Convert.ToInt32(((ListView)sender).DataKeys[e.ItemIndex].Value);
        new Document<InfoClient>().DelDoc<InfoClient>(ClientKey);
    }

    protected void lv_InfoDevice_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int DeviceKey = Convert.ToInt32(((ListView)sender).DataKeys[e.ItemIndex].Value);
        new Document<InfoDevice>().DelDoc<InfoDevice>(DeviceKey);
    }

    protected void lv_InfoOffice_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int OfficeKey = Convert.ToInt32(((ListView)sender).DataKeys[e.ItemIndex].Value);
        new Document<InfoOffice>().DelDoc<InfoOffice>(OfficeKey);
    }

    protected void lv_InfoSoft_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int SoftKey = Convert.ToInt32(((ListView)sender).DataKeys[e.ItemIndex].Value);
        new Document<InfoSoft>().DelDoc<InfoSoft>(SoftKey);
    }
}
